<?php

/*   __________________________________________________
    |  Obfuscated by YAK Pro - Php Obfuscator          |
    |              on 2018-07-17 15:19:57              |
    |    GitHub: https://github.com/pk-fr/yakpro-po    |
    |__________________________________________________|
*/
namespace Slj123Tongcheng\controller;

defined("IN_IA") || die("Access Denied");
class BaseController extends \Slj123_tongchengModuleSite
{
    public function __construct($Site, $arguments)
    {
        parent::__construct();
        $this->modulename = basename(dirname(dirname(dirname(__FILE__))));
        $file = IA_ROOT . "/addons/{$this->modulename}/module.php";
        if (!is_file($file)) {
            $file = IA_ROOT . "/framework/builtin/{$this->modulename}/module.php";
        }
        $this->__define = $file;
        load()->model("module");
        $this->module = module_fetch($this->modulename);
    }
    protected function template($filename = null)
    {
        $this->pageId = preg_replace("/.+?-controller-mobile-/", '', str_replace("\\", "-", get_called_class())) . (empty($GLOBALS["_GPC"]["ac"]) ? '' : "_" . $GLOBALS["_GPC"]["ac"]);
        empty($filename) && ($filename = "Controller/" . preg_replace("/.*?\\/controller\\//", '', str_replace("\\", "/", get_called_class())));
        $name = strtolower($this->modulename);
        $defineDir = dirname($this->__define);
        if (defined("IN_SYS")) {
            $compile = IA_ROOT . "/data/tpl/web/{$GLOBALS["_W"]["template"]}/{$name}/{$filename}.tpl.php";
            is_file($source = IA_ROOT . "/web/themes/{$GLOBALS["_W"]["template"]}/{$name}/{$filename}.html") || is_file($source = IA_ROOT . "/web/themes/default/{$name}/{$filename}.html") || is_file($source = IA_ROOT . "/web/themes/{$GLOBALS["_W"]["template"]}/{$filename}.html") || is_file($source = "{$defineDir}/template/Controller/web/{$filename}.html") || is_file($source = "{$defineDir}/template/Controller/web/" . (in_array($filename, array("header", "footer", "slide", "toolbar", "message", "nav")) ? "common/" : '') . "{$filename}.html") || ($source = IA_ROOT . "/web/themes/default/{$filename}.html");
        } else {
            $compile = IA_ROOT . "/data/tpl/app/{$GLOBALS["_W"]["template"]}/{$name}/{$filename}.tpl.php";
            is_file($source = IA_ROOT . "/app/themes/{$GLOBALS["_W"]["template"]}/{$name}/{$filename}.html") || is_file($source = IA_ROOT . "/app/themes/default/{$name}/{$filename}.html") || is_file($source = "{$defineDir}/template/mobile/{$filename}.html") || is_file($source = "{$defineDir}/template/mobile/" . (in_array($filename, array("header", "footer", "slide", "toolbar", "message")) ? "common/" : '') . "{$filename}.html") || is_file($source = "{$defineDir}/template/Controller/mobile/" . (in_array($filename, array("header", "footer", "slide", "toolbar", "message", "nav")) ? "common/" : '') . "{$filename}.html") || is_file($source = IA_ROOT . "/app/themes/{$GLOBALS["_W"]["template"]}/{$filename}.html") || ($source = IA_ROOT . "/app/themes/default/" . (in_array($filename, array("header", "footer", "slide", "toolbar", "message")) ? "common/" : '') . "{$filename}.html");
        }
        is_file($source) || is_file($source = "{$defineDir}/template/{$filename}.html") || exit("Error: template source '{$filename}' is not exist!");
        $paths = pathinfo($compile);
        $compile = str_replace($paths["filename"], $GLOBALS["_W"]["uniacid"] . "_" . $paths["filename"], $compile);
        (DEVELOPMENT || !is_file($compile) || filemtime($source) > filemtime($compile)) && template_compile($source, $compile, true);
        return $compile;
    }
    protected function mdate($time = null)
    {
        $time = strtotime($time);
        $now = time();
        $time = $time === null || $time > $now ? $now : intval($time);
        $t = $now - $time;
        $y = date("Y", $time) - date("Y", $now);
        switch ($t) {
            case $t < 60 * 30:
                $text = "刚刚";
                break;
            case $t < 60 * 60:
                $text = floor($t / 60) . "分钟前";
                break;
            case $t < 60 * 60 * 24:
                $text = floor($t / (60 * 60)) . "小时前";
                break;
            case $t < 60 * 60 * 24 * 3:
                $text = floor($time / (60 * 60 * 24)) == 1 ? "昨天 " . date("H:i", $time) : "前天 " . date("H:i", $time);
                break;
            case $t < 60 * 60 * 24 * 30:
                $text = date("m月d日 H:i", $time);
                break;
            case $t < 60 * 60 * 24 * 365 && $y == 0:
                $text = date("m月d日", $time);
                break;
            default:
                $text = date("Y年m月d日", $time);
                break;
        }
        return $text;
    }
    protected function getUniversalCall()
    {
        empty($GLOBALS["_GPC"]["Action"]) || empty($GLOBALS["_GPC"]["Method"]) || ($GLOBALS["_GPC"]["Action"] = preg_replace("/[^a-zA-Z]/", '', $GLOBALS["_GPC"]["Action"])) && ($GLOBALS["_GPC"]["Method"] = preg_replace("/[^a-zA-Z]/", '', $GLOBALS["_GPC"]["Method"])) && ($ActionClass = "NanpaiTicket{$GLOBALS["_GPC"]["Action"]}") && method_exists($ActionClass, $GLOBALS["_GPC"]["Method"]) && call_user_func_array(array($ActionClass, $GLOBALS["_GPC"]["Method"]), $GLOBALS["_GPC"]["Params"]);
    }
    public function convert_baidu_to_tengxun($lat, $lng)
    {
        $x_pi = 3.1415926535898 * 3000.0 / 180.0;
        $x = $lng - 0.0065;
        $y = $lat - 0.006;
        $z = sqrt($x * $x + $y * $y) - 2.0E-5 * sin($y * $x_pi);
        $theta = atan2($y, $x) - 3.0E-6 * cos($x * $x_pi);
        $lng = $z * cos($theta);
        $lat = $z * sin($theta);
        return array("lng" => $lng, "lat" => $lat);
    }
    public function convert_tengxun_to_baidu($lat, $lng)
    {
        $x_pi = 3.1415926535898 * 3000.0 / 180.0;
        $x = $lng;
        $y = $lat;
        $z = sqrt($x * $x + $y * $y) + 2.0E-5 * sin($y * $x_pi);
        $theta = atan2($y, $x) + 3.0E-6 * cos($x * $x_pi);
        $lng = $z * cos($theta) + 0.0065;
        $lat = $z * sin($theta) + 0.006;
        return array("lng" => $lng, "lat" => $lat);
    }
}